<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<html>
<head>
    <title>管理员查询</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/layui.css" />
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/common.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/slide.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/flat-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/jquery.nouislider.css">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/layui.js" media="all" ></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            $.ajax({
                type:"get",
                url:"${pageContext.request.contextPath }/admin/songList",
                data:{
                    pageNum:1
                },
                dataType:"json",
                success:function(data){
                    console.log(data);
                    var tr="";

                    $.each(data,function(index,info){
                        console.log(data)
                        tr+="<tr><td>"+info.songId+"</td><td>"+info.soName+"</td>"+
                            "<td>"+info.siName+"</td>"+"<td style='display: none'>"+info.singerId+"</td>"+
                            "<td>"+info.songType+"</td>"+"<td style='display: none'>"+info.typeId+"</td>"+"<td>"+info.soCollect+"</td>"+
                            "<td>"+info.cdName+"</td>"+"<td style='display: none'>"+info.cdId+"</td>"+"<td>"+info.isMV+"</td>"+
                            "<td><button id='updateSong' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateSon' value='"+info.songId+" '>修改</button>"+
                            "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.songId+" 'id='delSon'>删除</button></td><tr/>";
                    });

                    $("#table-lists").html(tr);
                    $("#prev").val(data.hasPreviousPage);
                    $("#next").val(data.hasNextPage);
                    $("#nowPage").val(data.pageNum);

                }
            });

            $("#p-button").on("click", "#bt", function(){
                $.ajax({
                    type:"get",
                    data:{
                        pageNum:$(this).val()
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                        var tr="";
                        $.each(data, function(index,info) {
                            tr+="<tr><td>"+info.songId+"</td><td>"+info.soName+"</td>"+
                                "<td>"+info.siName+"</td>"+"<td style='display: none'>"+info.singerId+"</td>"+
                                "<td>"+info.songType+"</td>"+"<td style='display: none'>"+info.typeId+"</td>"+"<td>"+info.soCollect+"</td>"+
                                "<td>"+info.cdName+"</td>"+"<td style='display: none'>"+info.cdId+"</td>"+"<td>"+info.isMV+"</td>"+
                                "<td><button id='updateSong'class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateSon' value='"+info.songId+" '>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.songId+" 'id='delSon'>删除</button></td><tr/>";
                        });
                    }
                });
            });

            //上一页
            $("#prev").click(function () {
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum =  $("#nowPage").val()-1;
                }
                $.ajax({
                    type:"get",

                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";
                        $.each(data, function(index,info) {
                            tr+="<tr><td>"+info.songId+"</td><td>"+info.soName+"</td>"+
                                "<td>"+info.siName+"</td>"+"<td style='display: none'>"+info.singerId+"</td>"+
                                "<td>"+info.songType+"</td>"+"<td style='display: none'>"+info.typeId+"</td>"+"<td>"+info.soCollect+"</td>"+
                                "<td>"+info.cdName+"</td>"+"<td style='display: none'>"+info.cdId+"</td>"+"<td>"+info.isMV+"</td>"+
                                "<td><button id='updateSong'class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateSon' value='"+info.songId+" '>修改</button>"+
                                "<button  class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.songId+" 'id='delSon'>删除</button></td><tr/>";
                        });
                        $("#table-lists").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })


            // 下一页
            $("#next").click(function () {
                console.log($(this).val())
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum = parseInt($("#nowPage").val())+1;
                    console.log(pageNum)
                }
                $.ajax({
                    type:"get",

                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";

                        $.each(data, function(index,info) {
                            tr+="<tr><td>"+info.songId+"</td><td>"+info.soName+"</td>"+
                                "<td>"+info.siName+"</td>"+"<td style='display: none'>"+info.singerId+"</td>"+
                                "<td>"+info.songType+"</td>"+"<td style='display: none'>"+info.typeId+"</td>"+"<td>"+info.soCollect+"</td>"+
                                "<td>"+info.cdName+"</td>"+"<td style='display: none'>"+info.cdId+"</td>"+"<td>"+info.isMV+"</td>"+
                                "<td><button id='updateSong' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateSon' value='"+info.songId+" '>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.songId+" 'id='delSon'>删除</button></td><tr/>";
                        });
                        $("#table-lists").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })

            // 关键字搜索
            $("#search").click(function () {
                $.ajax({
                    type: "get",
                    url: "${pageContext.request.contextPath}/admin/adminBySong",
                    dataType: "json",
                    data: {
                        keyword: $("#keyword").val()
                    },
                    success: function (data) {
                        if (data != "") {
                            var tr = "";
                            $.each(data, function (index, info) {
                                tr+="<tr><td>"+info.songId+"</td><td>"+info.soName+"</td>"+
                                    "<td>"+info.siName+"</td>"+"<td style='display: none'>"+info.singerId+"</td>"+
                                    "<td>"+info.songType+"</td>"+"<td style='display: none'>"+info.typeId+"</td>"+"<td>"+info.soCollect+"</td>"+
                                    "<td>"+info.cdName+"</td>"+"<td style='display: none'>"+info.cdId+"</td>"+"<td>"+info.isMV+"</td>"+
                                    "<td><button id='updateSong' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updateSon' value='"+info.songId+" '>修改</button>"+
                                    "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.songId+" 'id='delSon'>删除</button></td><tr/>";
                            });
                            $("#table-list").html(tr);
                        }else {
                            alert("没有该电影类别");
                        }

                    }

                })

            });
            //删除
            $("#table-lists").on("click", "#delSon", function() {
                console.log($(this).val())
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/songDel",
                    data:{
                        songId:$(this).val(),
                    },
                    dataType:"json",
                    success:function(data){
                        if (data==1){
                            alert("删除成功")
                        }else {
                            alert("删除失败")
                        }
                        location.href="${pageContext.request.contextPath }/admin/lastSong";
                    }
                });
            }) ;


            $("#table-lists").on("click", "#updateSong", function() {
              $("#songId").val($(this).closest("tr").find("td").eq(0).text())
               $("#soName").val($(this).closest("tr").find("td").eq(1).text())
                 $("#singerId").val($(this).closest("tr").find("td").eq(3).text())
                $("#typeId").val($(this).closest("tr").find("td").eq(5).text())
                 $("#soCollect").val($(this).closest("tr").find("td").eq(6).text())
                $("#cdId").val($(this).closest("tr").find("td").eq(8).text())
                $("#isMV").val($(this).closest("tr").find("td").eq(9).text())


            });


            $("#doSong").click(function () {
                console.log($("#songId").val());
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/doSongUpdate",
                    data:{
                        songId:$("#songId").val(),
                        soName:$("#soName").val(),
                        siId:$("#siId").val(),
                        soType:$("#soType").val(),
                        soCollect:$("#soCollect").val(),
                        cdId:$("#cdId").val(),
                        isMV:$("#isMV").val()
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        if (data!=null){
                            alert("修改成功");
                            window.location.href = "${pageContext.request.contextPath}/admin/lastSong";
                        }
                    }
                });
            });

            $("#adSong").click(function(){
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath}/admin/addSongs",
                    dataType:"text",
                    data:{
                        songId:$("#songIds").val(),
                        soName:$("#soNames").val(),
                        siId:$("#siIds").val(),
                        soType:$("#soTypes").val(),
                        soCollect:$("#soCollects").val(),
                        cdId:$("#cdIds").val(),
                        isMV:$("#isMVs").val()
                    },
                    success:function(data){
                        if (data==1) {
                            alert("添加成功");
                            location.href="${pageContext.request.contextPath}/admin/lastSong";
                        }
                    }, error:function(){
                        alert("系统崩溃！");
                    }
                });
            })
        });
    </script>
</head>
<body>
<div role="tabpanel" class="tab-pane" id="char">
    <div class="check-div form-inline">
        <div class="col-xs-3" style="padding-top: 25px">
            <button class="btn btn-yellow btn-xs" data-toggle="modal" data-target="#myModalAddSong">添加歌曲 </button>
        </div>
        <div class="col-lg-4 col-xs-5">
            <input type="text" class=" form-control input-sm " placeholder="输入文字搜索" id="keyword">
            <button class="btn btn-white btn-xs " id="search">查 询 </button>
        </div>

    </div>
    <table class="table text-center" id="tab">
        <thead>
        <tr>
            <th>编号</th>
            <th>歌名</th>
            <th>歌手</th>
            <th>歌曲分类</th>
            <th>收藏数</th>
            <th>所属专辑</th>
            <th>是否有MV</th>
            <th colspan="2">操作</th>
        </tr>
        </thead>
        <tbody id="table-lists">

        </tbody>

        <tbody>
       <%-- <tr class="text-center">
            <td colspan="12">
                <button data-target="#myModalAddSong" data-toggle="modal">添加</button>

            </td>
        </tr>--%>
        </tbody>

    </table>
</div>

<%--
<!-- 修改模态框（Modal） -->
<div class="modal fade" id="updateSon" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改用户
                </h4>
            </div>
            <div class="modal-body">

                <input type="hidden" id="songId"/>
                歌名：<input type="text" id="soName"/><br/>
                歌手：<select id="siId">
                <option value="1">CJY</option>
                <option value="2">HHZ</option>
            </select><br/>
                歌曲分类：<select id="soType">
                <option value="1">爱情</option>
                <option value="2">激情</option>
            </select>
                <br/>
                收藏数：<input type="text" id="soCollect"/><br/>
                所属专辑:<select id="cdId">
                <option value="1">重生之我是CJY</option>
                <option value="2">杀杀ss杀</option>
            </select>
                <br/>
                是否有MV<select id="isMV">
                <option value="1">有</option>
                <option value="0">没有</option>
            </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="doSong">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
--%>
<!--修改用户弹出窗口-->
<div class="modal fade" id="updateSon" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">修改歌曲信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="songId"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-3 control-label">歌名：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="soName" class="form-control input-sm duiqi" id="sName" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">歌手：</label>
                            <div class="col-xs-6 ">
                                <select id="siId">
                                    <option value="1">李宇春</option>
                                    <option value="2">周笔畅</option>
                                    <option value="3">鹿晗</option>
                                    <option value="4">张艺兴</option>
                                    <option value="5">林俊杰</option>
                                    <option value="6">
                                        允儿 (윤아)</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sOrd" class="col-xs-3 control-label">类型：</label>
                            <div class="col-xs-6">
                                <select id="soType">
                                    <option value="1">爱情</option>
                                    <option value="2">欢乐</option>
                                    <option value="3">BOX</option>
                                    <option value="4">DJ</option>
                                    <option value="5">抒情</option>

                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">收藏量：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="soCollect" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">专辑：</label>
                            <div class="col-xs-6 ">
                                <select id="cdId">
                                    <option value="3">π-volume.1</option>
                                    <option value="4">HONEY</option>
                                    <option value="2">LUNAR</option>
                                    <option value="6">A Walk to Remember - Special Album</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">是否MV：</label>
                            <div class="col-xs-6 ">
                                <select id="isMV">
                                <option value="1">有</option>
                                <option value="0">没有</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green" id="doSong">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->

</div>
<%--<!-- 模态框（Modal） -->
<div class="modal fade" id="myModalAddSong" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabels">
                    添加用户
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="songIds"/>
                歌名：<input type="text" id="soNames" /><br/>
                歌手：<select id="siIds">
                <option value="1">CJY</option>
                <option value="2">HHZ</option>
            </select><br/>
                歌曲分类：<select id="soTypes">
                <option value="1">激情</option>
                <option value="2">爱情</option>
            </select>
                <br/>
                收藏数：<input type="text" id="soCollects" /><br/>
                所属专辑:<select id="cdIds">
                <option value="1">重生之我是CJY</option>
                <option value="2">杀杀ss杀</option>
            </select>
                <br/>
                是否有MV<select id="isMVs">
                <option value="1">有</option>
                <option value="0">没有</option>
            </select>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="adSong">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->--%>
<!--增加权限弹出窗口-->
<div class="modal fade" id="myModalAddSong" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">添加权限</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="songIds"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-3 control-label">歌名：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="soNames" class="form-control input-sm duiqi" id="sName" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">歌手：</label>
                            <div class="col-xs-6 ">
                                <select id="siIds">
                                    <option value="1">李宇春</option>
                                    <option value="2">周笔畅</option>
                                    <option value="3">鹿晗</option>
                                    <option value="4">张艺兴</option>
                                    <option value="5">林俊杰</option>
                                    <option value="6">
                                        允儿 (윤아)</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sOrd" class="col-xs-3 control-label">类型：</label>
                            <div class="col-xs-6">
                                <select id="soTypes">
                                    <option value="1">爱情</option>
                                    <option value="2">欢乐</option>
                                    <option value="3">BOX</option>
                                    <option value="4">DJ</option>
                                    <option value="5">抒情</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">收藏量：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="soCollects" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">专辑：</label>
                            <div class="col-xs-6 ">
                                <select id="cdIds">
                                    <option value="3">π-volume.1</option>
                                    <option value="4">HONEY</option>
                                    <option value="2">LUNAR</option>
                                    <option value="6">A Walk to Remember - Special Album</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">是否MV：</label>
                            <div class="col-xs-6 ">
                                <select id="isMVs">
                                    <option value="1">有</option>
                                    <option value="0">没有</option>
                                </select>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green"  id="adSong">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>
<!-- /.modal -->


</div>
<p style="text-align: center" id="p-button">
    <button class="btn btn-info" id="prev">上一页</button>
    <button class="btn btn-info" id="bt" value="1">第1页</button>
    <button class="btn btn-info" id="bt" value="2">第2页</button>
    <button class="btn btn-info" id="bt" value="3">第3页</button>
    <button class="btn btn-info" id="next">下一页</button>
</p>
<input type="hidden" id="nowPage"/>
</body>
</html>
